home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / include / libpurple / sslconn.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-04  |  5.8 KB  |  213 lines

  1. /**
  2.  * @file sslconn.h SSL API
  3.  * @ingroup core
  4.  *
  5.  * purple
  6.  *
  7.  * Purple is the legal property of its developers, whose names are too numerous
  8.  * to list here.  Please refer to the COPYRIGHT file distributed with this
  9.  * source distribution.
  10.  *
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  24.  */
  25. #ifndef _PURPLE_SSLCONN_H_
  26. #define _PURPLE_SSLCONN_H_
  27.  
  28. #include "proxy.h"
  29.  
  30. #define PURPLE_SSL_DEFAULT_PORT 443
  31.  
  32. typedef enum
  33. {
  34.     PURPLE_SSL_HANDSHAKE_FAILED = 1,
  35.     PURPLE_SSL_CONNECT_FAILED = 2
  36. } PurpleSslErrorType;
  37.  
  38. typedef struct _PurpleSslConnection PurpleSslConnection;
  39.  
  40. typedef void (*PurpleSslInputFunction)(gpointer, PurpleSslConnection *,
  41.                                      PurpleInputCondition);
  42. typedef void (*PurpleSslErrorFunction)(PurpleSslConnection *, PurpleSslErrorType,
  43.                                      gpointer);
  44.  
  45. struct _PurpleSslConnection
  46. {
  47.     char *host;
  48.     int port;
  49.     void *connect_cb_data;
  50.     PurpleSslInputFunction connect_cb;
  51.     PurpleSslErrorFunction error_cb;
  52.     void *recv_cb_data;
  53.     PurpleSslInputFunction recv_cb;
  54.  
  55.     int fd;
  56.     int inpa;
  57.     PurpleProxyConnectData *connect_data;
  58.  
  59.     void *private_data;
  60. };
  61.  
  62. /**
  63.  * SSL implementation operations structure.
  64.  *
  65.  * Every SSL implementation must provide all of these and register it.
  66.  */
  67. typedef struct
  68. {
  69.     gboolean (*init)(void);
  70.     void (*uninit)(void);
  71.     void (*connectfunc)(PurpleSslConnection *gsc);
  72.     void (*close)(PurpleSslConnection *gsc);
  73.     size_t (*read)(PurpleSslConnection *gsc, void *data, size_t len);
  74.     size_t (*write)(PurpleSslConnection *gsc, const void *data, size_t len);
  75.  
  76.     void (*_purple_reserved1)(void);
  77.     void (*_purple_reserved2)(void);
  78.     void (*_purple_reserved3)(void);
  79.     void (*_purple_reserved4)(void);
  80. } PurpleSslOps;
  81.  
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85.  
  86. /**************************************************************************/
  87. /** @name SSL API                                                         */
  88. /**************************************************************************/
  89. /*@{*/
  90.  
  91. /**
  92.  * Returns whether or not SSL is currently supported.
  93.  *
  94.  * @return TRUE if SSL is supported, or FALSE otherwise.
  95.  */
  96. gboolean purple_ssl_is_supported(void);
  97.  
  98. /**
  99.  * Makes a SSL connection to the specified host and port.  The caller
  100.  * should keep track of the returned value and use it to cancel the
  101.  * connection, if needed.
  102.  *
  103.  * @param account    The account making the connection.
  104.  * @param host       The destination host.
  105.  * @param port       The destination port.
  106.  * @param func       The SSL input handler function.
  107.  * @param error_func The SSL error handler function.  This function
  108.  *                   should NOT call purple_ssl_close().  In the event
  109.  *                   of an error the PurpleSslConnection will be
  110.  *                   destroyed for you.
  111.  * @param data       User-defined data.
  112.  *
  113.  * @return The SSL connection handle.
  114.  */
  115. PurpleSslConnection *purple_ssl_connect(PurpleAccount *account, const char *host,
  116.                                     int port, PurpleSslInputFunction func,
  117.                                     PurpleSslErrorFunction error_func,
  118.                                     void *data);
  119.  
  120. /**
  121.  * Makes a SSL connection using an already open file descriptor.
  122.  *
  123.  * @param account    The account making the connection.
  124.  * @param fd         The file descriptor.
  125.  * @param func       The SSL input handler function.
  126.  * @param error_func The SSL error handler function.
  127.  * @param data       User-defined data.
  128.  *
  129.  * @return The SSL connection handle.
  130.  */
  131. PurpleSslConnection *purple_ssl_connect_fd(PurpleAccount *account, int fd,
  132.                                        PurpleSslInputFunction func,
  133.                                        PurpleSslErrorFunction error_func,
  134.                                        void *data);
  135.  
  136. /**
  137.  * Adds an input watcher for the specified SSL connection.
  138.  *
  139.  * @param gsc   The SSL connection handle.
  140.  * @param func  The callback function.
  141.  * @param data  User-defined data.
  142.  */
  143. void purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func,
  144.                         void *data);
  145.  
  146. /**
  147.  * Closes a SSL connection.
  148.  *
  149.  * @param gsc The SSL connection to close.
  150.  */
  151. void purple_ssl_close(PurpleSslConnection *gsc);
  152.  
  153. /**
  154.  * Reads data from an SSL connection.
  155.  *
  156.  * @param gsc    The SSL connection handle.
  157.  * @param buffer The destination buffer.
  158.  * @param len    The maximum number of bytes to read.
  159.  *
  160.  * @return The number of bytes read.
  161.  */
  162. size_t purple_ssl_read(PurpleSslConnection *gsc, void *buffer, size_t len);
  163.  
  164. /**
  165.  * Writes data to an SSL connection.
  166.  *
  167.  * @param gsc    The SSL connection handle.
  168.  * @param buffer The buffer to write.
  169.  * @param len    The length of the data to write.
  170.  *
  171.  * @return The number of bytes written.
  172.  */
  173. size_t purple_ssl_write(PurpleSslConnection *gsc, const void *buffer, size_t len);
  174.  
  175. /*@}*/
  176.  
  177. /**************************************************************************/
  178. /** @name Subsystem API                                                   */
  179. /**************************************************************************/
  180. /*@{*/
  181.  
  182. /**
  183.  * Sets the current SSL operations structure.
  184.  *
  185.  * @param ops The SSL operations structure to assign.
  186.  */
  187. void purple_ssl_set_ops(PurpleSslOps *ops);
  188.  
  189. /**
  190.  * Returns the current SSL operations structure.
  191.  *
  192.  * @return The SSL operations structure.
  193.  */
  194. PurpleSslOps *purple_ssl_get_ops(void);
  195.  
  196. /**
  197.  * Initializes the SSL subsystem.
  198.  */
  199. void purple_ssl_init(void);
  200.  
  201. /**
  202.  * Uninitializes the SSL subsystem.
  203.  */
  204. void purple_ssl_uninit(void);
  205.  
  206. /*@}*/
  207.  
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211.  
  212. #endif /* _PURPLE_SSLCONN_H_ */
  213.